package com.gaofeng.day22.a07ThreadDemo;

public class MyThread  extends Thread{
    static  int ticket = 0;

    //锁对象一定要是唯一的
//   static Object obj = new Object();

    @Override
    public void run() {
        while (true){
            synchronized (MyThread.class){
                if(ticket < 100){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    ticket++;
                    System.out.println(getName()+ "正在卖第 "+ticket +" 张票");
                }else{
                    break;
                }
            }
        }
    }
}
